package com.gitee.zycra.union.api.common.vo;

import com.gitee.zycra.union.api.common.model.ApiUser;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author zycra
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class UserVO {

    /**
     * 主键
     */
    private Long id;

    /**
     * 用户名
     */
    private String username;

    /**
     * 是否启用
     */
    private Boolean enabled;

    /**
     * 是否是超级管理员
     */
    private Boolean superAdmin;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 上次尝试登录时间
     */
    private LocalDateTime lastLoginTime;

    /**
     * 权限组
     */
    private List<UserAuthVO> authGroup;

    public static UserVO buildApiUserVO(ApiUser apiUser, List<UserAuthVO> authGroup) {
        if (apiUser == null) {
            return null;
        }
        return new UserVO()
                .setId(apiUser.getId())
                .setLastLoginTime(apiUser.getLastLoginTime())
                .setEnabled(apiUser.getEnabled())
                .setUsername(apiUser.getUsername())
                .setSuperAdmin(apiUser.getSuperAdmin())
                .setCreateTime(apiUser.getCreateTime())
                .setUpdateTime(apiUser.getUpdateTime())
                .setAuthGroup(authGroup);
    }
}
